From c74cf9f7717317fc224cf548c023509ec163771b Mon Sep 17 00:00:00 2001 From: Paul Donald Date: Tue, 23 Sep 2025 14:42:35 +0200 Subject: [PATCH] luci-app-ddns: improve accuracy of next update and check times Depends on https://github.com/openwrt/packages/pull/27473 Refactor their display also. Signed-off-by: Paul Donald --- .../resources/view/ddns/overview.js | 63 +++++++------------ .../root/usr/share/rpcd/ucode/ddns.uc | 16 +++-- 2 files changed, 33 insertions(+), 46 deletions(-) diff --git a/applications/luci-app-ddns/htdocs/luci-static/resources/view/ddns/overview.js b/applications/luci-app-ddns/htdocs/luci-static/resources/view/ddns/overview.js index 2a11193c74..f87931ec59 100644 --- a/applications/luci-app-ddns/htdocs/luci-static/resources/view/ddns/overview.js +++ b/applications/luci-app-ddns/htdocs/luci-static/resources/view/ddns/overview.js @@ -192,8 +192,6 @@ return view.extend({ poll_status: function(map, data) { var status = data[1] || [], service = data[0] || [], rows = map.querySelectorAll('.cbi-section-table-row[data-sid]'), - section_id, cfg_detail_ip, cfg_update, cfg_status, host, ip, last_update, - next_update, service_status, reload, cfg_enabled, stop, ddns_enabled = map.querySelector('[data-name="_enabled"]').querySelector('.cbi-value-field'), ddns_toggle = map.querySelector('[data-name="_toggle"]').querySelector('button'), services_list = map.querySelector('[data-name="_services_list"]').querySelector('.cbi-value-field'); @@ -212,36 +210,26 @@ return view.extend({ }); for (var i = 0; i < rows.length; i++) { - section_id = rows[i].getAttribute('data-sid'); - cfg_detail_ip = rows[i].querySelector('[data-name="_cfg_detail_ip"]'); - cfg_update = rows[i].querySelector('[data-name="_cfg_update"]'); - cfg_status = rows[i].querySelector('[data-name="_cfg_status"]'); - reload = rows[i].querySelector('.cbi-section-actions .reload'); - stop = rows[i].querySelector('.cbi-section-actions .stop'); - cfg_enabled = uci.get('ddns', section_id, 'enabled'); + const section_id = rows[i].getAttribute('data-sid'); + const cfg_detail_ip = rows[i].querySelector('[data-name="_cfg_detail_ip"]'); + const cfg_update = rows[i].querySelector('[data-name="_cfg_update"]'); + const cfg_status = rows[i].querySelector('[data-name="_cfg_status"]'); + const reload = rows[i].querySelector('.cbi-section-actions .reload'); + const stop = rows[i].querySelector('.cbi-section-actions .stop'); + const cfg_enabled = uci.get('ddns', section_id, 'enabled'); reload.disabled = (status['_enabled'] == 0 || cfg_enabled == 0); + stop.disabled = (!service[section_id].pid); - host = uci.get('ddns', section_id, 'lookup_host') || _('Configuration Error'); - ip = _('No Data'); - last_update = _('Never'); - next_update = _('Unknown'); - service_status = '' + _('Not Running') + ''; - - if (service[section_id]) { - stop.disabled = (!service[section_id].pid); - if (service[section_id].ip) - ip = service[section_id].ip; - if (service[section_id].last_update) - last_update = service[section_id].last_update; - if (service[section_id].next_update) - next_update = this.NextUpdateStrings[service[section_id].next_update] || service[section_id].next_update; - if (service[section_id].pid) - service_status = '' + _('Running') + ' : ' + service[section_id].pid; - } + const host = uci.get('ddns', section_id, 'lookup_host') || _('Configuration Error'); + const ip = service[section_id]?.ip || _('No Data'); + const last_update = service[section_id]?.last_update || _('Never'); + const next_update = this.NextUpdateStrings[service[section_id]?.next_update] || service[section_id]?.next_update || _('Unknown'); + const next_check = service[section_id]?.next_check || _('Unknown'); + const service_status = service[section_id]?.pid ? '' + _('Running') + ' : ' + service[section_id]?.pid : '' + _('Not Running') + ''; cfg_detail_ip.innerHTML = host + '
' + ip; - cfg_update.innerHTML = last_update + '
' + next_update; + cfg_update.innerHTML = last_update + '
' + next_check + '
' + next_update ; cfg_status.innerHTML = service_status; } @@ -1144,10 +1132,8 @@ return view.extend({ o.rawhtml = true; o.modalonly = false; o.textvalue = function(section_id) { - var host = uci.get('ddns', section_id, 'lookup_host') || _('Configuration Error'), - ip = _('No Data'); - if (resolved[section_id] && resolved[section_id].ip) - ip = resolved[section_id].ip; + const host = uci.get('ddns', section_id, 'lookup_host') || _('Configuration Error'); + const ip = resolved[section_id]?.ip || _('No Data'); return host + '
' + ip; }; @@ -1157,19 +1143,14 @@ return view.extend({ o.editable = true; o.modalonly = false; - o = s.option(form.DummyValue, '_cfg_update', _('Last Update') + "
" + _('Next Update')); + o = s.option(form.DummyValue, '_cfg_update', _('Last Update') + " |
" + _('Next Verify') + " |
" + _('Next Update')); o.rawhtml = true; o.modalonly = false; o.textvalue = function(section_id) { - var last_update = _('Never'), next_update = _('Unknown'); - if (resolved[section_id]) { - if (resolved[section_id].last_update) - last_update = resolved[section_id].last_update; - if (resolved[section_id].next_update) - next_update = _this.NextUpdateStrings[resolved[section_id].next_update] || resolved[section_id].next_update; - } - - return last_update + '
' + next_update; + const last_update = resolved[section_id]?.last_update || _('Never'); + const next_check = resolved[section_id]?.next_check || _('Unknown'); + const next_update = _this.NextUpdateStrings[resolved[section_id]?.next_update] || resolved[section_id]?.next_update || _('Unknown'); + return last_update + '
' + next_check + '
' + next_update; }; return m.render().then(L.bind(function(m, nodes) { diff --git a/applications/luci-app-ddns/root/usr/share/rpcd/ucode/ddns.uc b/applications/luci-app-ddns/root/usr/share/rpcd/ucode/ddns.uc index ecd41fa1ce..f8901a0a30 100644 --- a/applications/luci-app-ddns/root/usr/share/rpcd/ucode/ddns.uc +++ b/applications/luci-app-ddns/root/usr/share/rpcd/ucode/ddns.uc @@ -12,8 +12,6 @@ const ddns_log_path = '/var/log/ddns'; const ddns_package_path = '/usr/share/ddns'; const ddns_run_path = '/var/run/ddns'; const luci_helper = '/usr/lib/ddns/dynamic_dns_lucihelper.sh'; -const srv_name = 'ddns-scripts'; -const opkg_info_path = '/usr/lib/opkg/info'; const ddns_version_file = '/usr/share/ddns/version'; @@ -107,7 +105,7 @@ const methods = { uci.foreach('ddns', 'service', function(s) { /* uci.foreach danger zone: if you inadvertently call uci.unload('ddns') anywhere in this foreach loop, you will produce some spectacular undefined behaviour */ - let ip, lastUpdate, nextUpdate; + let ip, lastUpdate, nextUpdate, nextCheck; const section = s['.name']; if (section == '.anonymous') return; @@ -137,6 +135,7 @@ const methods = { } lastUpdate = int(readfile(`${rundir}/${section}.update`) || 0); + nextCheck = int(readfile(`${rundir}/${section}.nextcheck`) || 0); let pid = int(readfile(`${rundir}/${section}.pid`) || 0); @@ -161,10 +160,16 @@ const methods = { if (lastUpdate > 0) { const epoch = time() - _uptime + lastUpdate; convertedLastUpdate = epoch2date(epoch); - nextUpdate = epoch2date(epoch + forcedUpdateInterval + checkInterval); + nextUpdate = epoch2date(epoch + forcedUpdateInterval); } - if (pid > 0 && (lastUpdate + forcedUpdateInterval + checkInterval - _uptime) <= 0) { + let convertedNextCheck; + if (nextCheck > 0) { + const epoch = time() - _uptime + nextCheck; + convertedNextCheck = epoch2date(epoch); + } + + if (pid > 0 && (lastUpdate + forcedUpdateInterval - _uptime) <= 0) { nextUpdate = 'Verify'; } else if (forcedUpdateInterval === 0) { nextUpdate = 'Run once'; @@ -178,6 +183,7 @@ const methods = { ip: ip ? replace(trim(ip), '\n', '
') : null, last_update: lastUpdate !== 0 ? convertedLastUpdate : null, next_update: nextUpdate || null, + next_check : nextCheck !== 0 ? convertedNextCheck : null, pid: pid || null, }; }); -- 2.30.2